package com.zlkj.pro.modular.business.controller;

import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import com.zlkj.pro.modular.business.model.dto.ReportDTO;
import com.zlkj.pro.modular.business.model.vo.ReportFlowVO;
import com.zlkj.pro.modular.business.model.vo.ReportVO;
import com.zlkj.pro.modular.business.service.ReportService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

import static com.zlkj.pro.core.consts.ProjectConstants.SERVICE_API_PREFIX;

/**
 * @author liyang
 * @date 2024/4/6
 * @time 14:34
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@ApiResource(name = "报备单信息", path = SERVICE_API_PREFIX + "/report")
public class ReportController {

    private final ReportService reportService;

    @GetResource(name = "报备单列表", path = "/findPage")
    public ResponseData findPage(ReportDTO dto) {
        if (dto.getStatus() == null || dto.getStatus() == 0) {
            dto.setStatus(1);
        }
        if (dto.getStatus() == 3) {
            dto.setCertificateStatus(1);
        }
        Map<String,Object> map = reportService.findPage(dto);
        return new SuccessResponseData(map);
    }

    @GetResource(name = "报备单列表", path = "/findPageDone")
    public ResponseData findPageDone(ReportDTO dto) {
        if (dto.getStatus() == null || dto.getStatus() == 0) {
            dto.setStatus(3);
        }
        if (dto.getStatus() == 3) {
            dto.setCertificateStatus(2);
        }
        Map<String,Object> map = reportService.findPage(dto);
        return new SuccessResponseData(map);
    }

    @GetResource(name = "报备单详情", path = "/getDetail")
    public ResponseData getWebDetail(Long id) {
        ReportVO restData = reportService.getWebDetail(id);
        return new SuccessResponseData(restData);
    }


    @PostResource(name = "报备单审批", path = "/approve")
    public ResponseData approve(@RequestBody ReportDTO dto) {
        Boolean restData = reportService.approve(dto);
        return new SuccessResponseData(restData);
    }


    @PostResource(name = "补全书名号", path = "/fixCerCode")
    public ResponseData fixCerCode(@RequestBody ReportDTO dto) {
        Boolean restData = reportService.fixCerCode(dto);
        return new SuccessResponseData(restData);
    }

    @PostResource(name = "出货", path = "/fixSellCode")
    public ResponseData fixSellCode(@RequestBody ReportDTO dto) {
        Boolean restData = reportService.fixSellCode(dto);
        return new SuccessResponseData(restData);
    }

    @PostResource(name = "确认书名号", path = "/confirmCerCode")
    public ResponseData confirmCerCode(@RequestBody ReportDTO dto) {
        Boolean restData = reportService.confirmCerCode(dto);
        return new SuccessResponseData(restData);
    }

    @GetResource(name = "报备单流程列表", path = "/getFlow")
    public ResponseData getFlow(Long id) {
        List<ReportFlowVO> restData = reportService.getFlow(id);
        return new SuccessResponseData(restData);
    }
}
